//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by apple on 15/11/8.
//  Copyright © 2015年 apple. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    @objc private func composeDidClick() {
     //创建一个控制器
      let compose = ComposeController()
        
      let nav = UINavigationController(rootViewController: compose)
        
      presentViewController(nav, animated: true, completion: nil)
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabbar = MainTabbar()
        
        setValue(mainTabbar, forKey: "tabBar")
        
        // print(tabBar.classForCoder)  //打印当前的tabbar 为那个tabbar
        mainTabbar.compaseBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)  //点击按钮需要做的事情
        
        addcClildView()
      }

    private func addcClildView() {
    
      addChildViewConTrollers(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
      addChildViewConTrollers(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
      addChildViewConTrollers(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
      addChildViewConTrollers(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    private func addChildViewConTrollers(vc: UIViewController, title: String, imageName: String) {
        //实例化一个导航控制器
        let nav = NavController(rootViewController: vc)
        self.tabBar.tintColor = UIColor.orangeColor() //设置tabbar 的颜色为 黄色的
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        addChildViewController(nav)
    }
    
}
